-- soul_collect
-- created by chendh
-- 每杀死一个有生命的敌人，可以收割灵魂、增加属性

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 击杀触发
    trigger = function(who, prop, arg)
        local target = arg;
        if not FormulaM.invoke("IS_LIVING_TARGET", target) then
            -- 不是有生命的敌人，直接返回
            return;
        end

        local attrib = prop[2];

        local soul_collect = ME.user.dbase:query(attrib, 0);
        ME.user.dbase:set(attrib, soul_collect + prop[3]);

        -- 尝试合成世界树之心
        PropM.trigger(ME.user, "soul_to_item", 7158);

        local pos = target:getPos();

        EventMgr.fire(event.SOUL_COLLECT, {["amount"] = prop[3], ["pos"] = pos, ["attrib"] = attrib });

        return true;
    end,

    record = function(target, prop, path)
        return false;
    end
};
